﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;
using WOWMultiPlay;
using System.Reflection;

namespace VKFinder
{
    public class Control_VKFinderTextBox : TextBox
    {
        int PressedKey;

        protected override void WndProc(ref Message WinMsg)
        {
            if (WinMsg.Msg == Helper_Win32API.WM.WM_KEYDOWN)
            {
                PressedKey = WinMsg.WParam.ToInt32();
                this.Text += "{" + GetVKName(PressedKey) + "}";
                //base.WndProc(ref WinMsg);
            }
            else
            {
                base.WndProc(ref WinMsg);
            }
        }

        private string GetVKName(int VK)
        {
            Assembly Asm = Assembly.GetExecutingAssembly();
            Type TypeWin32API = Asm.GetType("WOWMultiPlay.Helper_Win32API");
            Type TypeVK = TypeWin32API.GetNestedType("VK");

            FieldInfo[] FIs = TypeVK.GetFields();
            foreach (FieldInfo FI in FIs)
            {
                if ((int)FI.GetValue(null) == VK)
                    return FI.Name;
            }

            return string.Empty;
        }
    }
}
